//
//  HealthDetailView.m
//  LoveHealth
//
//  Created by 陈永坤 on 14-9-22.
//  Copyright (c) 2014年 lanou. All rights reserved.
//

#import "HealthDetailView.h"

@implementation HealthDetailView



- (void)dealloc
{
    self.detailImageView = nil;
    self.detailScrollView = nil;
    self.detailTitleLabel = nil;
    self.detailWebView = nil;
    [super dealloc];
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self p_setupSubviews];
    }
    return self;
}


- (void)p_setupSubviews
{
    
    //添加title  标题
    _detailTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 64, self.bounds.size.width, 25)];
    _detailTitleLabel.backgroundColor = [UIColor grayColor];
    _detailTitleLabel.font = [UIFont systemFontOfSize:16.0];
    _detailTitleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_detailTitleLabel];
    
    
    //添加scrollView  滚动视图
    _detailScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 89, self.frame.size.width, self.frame.size.height - 64-25)];

    [self addSubview:_detailScrollView];
    
    
    
    
    //添加ImageView
    _detailImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 215)];
    //    _newsDetailImageView.image = [UIImage imageNamed:@""];
    //_detailImageView.backgroundColor = [UIColor grayColor];
    _detailImageView.contentMode = UIViewContentModeScaleAspectFill;
    _detailImageView.clipsToBounds = YES;
    [self.detailScrollView addSubview:_detailImageView];
    
    
    //添加资讯内容
    _detailWebView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 220, self.bounds.size.width - 20, 10)];
    //_detailWebView.backgroundColor = [UIColor clearColor];
    _detailWebView.scrollView.scrollEnabled = NO;
    [self.detailScrollView addSubview:_detailWebView];
    _detailWebView.delegate = self;
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSArray *arr = [webView subviews];
    UIScrollView *scrollView = [arr objectAtIndex:0];
    
    CGRect webViewFrame = webView.frame;
    //webViewFrame.origin.y = self.detailImageView.image.size.height + self.detailImageView.frame.origin.y;
    webViewFrame.size.height = scrollView.contentSize.height;
    NSLog(@"%f",scrollView.contentSize.height);
    webView.frame = webViewFrame;
    
    self.detailScrollView.contentSize = CGSizeMake(320, scrollView.contentSize.height + 220);
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
